package com.work.dao.impl;

import com.work.bean.Class;
import com.work.dao.BaseDao;
import com.work.dao.ClassDao;

import java.util.List;

public class ClassDaoImpl extends BaseDao implements ClassDao {
    public List<Class> queryClass() {
        String sql = "SELECT * FROM t_class  ";
        return  queryForList(Class.class,sql);
    }

    public Class queryClassById(Integer id) {
        String sql = "SELECT * FROM t_class  WHERE id = ?";
        return  queryForOne(Class.class,sql,id);
    }

    public int saveClass(Class c) {
        String sql = "INSERT INTO `t_class` (`cname`) VALUES (?)";
        return update(sql,c.getCname());
    }

    public int updateClass(Class c) {
        String sql = "UPDATE t_class SET `cname`=? WHERE `id` = ?";
        return update(sql,c.getCname(),c.getId());
    }

    public int deleteClass(Integer id) {
        String sql = "DELETE FROM `t_class` WHERE `id` = ?";
        return update(sql, id);
    }
}
